import {Component, OnInit} from '@angular/core';
import {_HttpClient} from '@delon/theme';
import {ActivatedRoute, Router} from '@angular/router';
import {UtilityService} from '../../../service/utils.service';
import {NzModalService, NzNotificationService} from 'ng-zorro-antd';
import {appConfig} from '../../../service/common';
import {AppliaModule} from '../../../service/common.module';

@Component({
  selector: 'app-function',
  templateUrl: './function.component.html',
    styleUrls: ['./function.component.less']
})
export class FunctionComponent implements OnInit {
    appGuid: any;
    appName: string;
    // 布局样式
    widthLeft = 8;
    widthRight = 16;
    isShow = true;
    text='收起'

    // 自定义卡片收缩方法
    toggleCollapsed(): void {
        this.isShow = !this.isShow;
        if(this.isShow === true){
            this.widthLeft = 8;
            this.widthRight = 16;
            this.text = '收起'
        }else{
            this.widthLeft = 2;
            this.widthRight = 22;
            this.text = '展开'
        }
    }
    tabs = [
        {
            name   : '功能',
            router : 'function/funcActive'
        },
        {
            name   : '个性化配置',
            router : 'function/appconfig'
        }
    ]


    // 应用的数据值
    appItem: AppliaModule = new AppliaModule(); // 搜索值

    appselectId: string;

    constructor(
        private http: _HttpClient,
        private router: Router,
        public activatedRoute: ActivatedRoute,
        private utilityService: UtilityService,
        private modal: NzModalService,
        private nznot: NzNotificationService
    ) { }

    ngOnInit() {
        this.activatedRoute.queryParams.subscribe(queryParams => {
            this.appGuid = queryParams.productId;
        });
        if(this.appGuid && this.appGuid != undefined){
            localStorage.setItem('appGuid', this.appGuid);
        }else{
            this.appGuid = localStorage.getItem('appGuid');// 运行环境ID本地存储
        }
        this.appselectId = this.appGuid;
        this.router.navigate(['function/funcActive', this.appselectId]); // 默认跳转第一个路由
        this.getData(); // 根据guid查询应用信息
    }


    getData() {
        // 根据guid查询应用信息
        this.utilityService.getData(appConfig.serverUrl + appConfig.API.appDed + '/' + this.appGuid)
            .subscribe(
                (val) => {
                    this.appItem = val.result;
                    this.appName = val.result.appName;
                }
            );

    }

    // 360切换
    getRouter(it){
        console.log(it)
        this.router.navigate([it, this.appselectId]);
    }
}


/* 重写逻辑 */
/*
import {Component, Inject, OnInit, Optional} from '@angular/core';
import {_HttpClient} from '@delon/theme';
import {ActivatedRoute, Router} from '@angular/router';
import {UtilityService} from '../../../service/utils.service';
import {NzModalService, NzNotificationService} from 'ng-zorro-antd';
import {appConfig} from '../../../service/common';
import {AppConfigModule, AppliaModule, FuncattrModule} from '../../../service/common.module';
import {FuncModule} from '../../../service/function/func.model';
import { CommondictServe} from '../../../service/commonDict';
import {ReuseTabService} from '@delon/abc';

@Component({
    selector: 'app-function',
    templateUrl: './function.component.html',
    styleUrls: ['./function.component.less']
})
export class FunctionComponent implements OnInit {

    constructor(
        private http: _HttpClient,
        private router: Router,
        public activatedRoute: ActivatedRoute,
        private utilityService: UtilityService,
        private modal: NzModalService,
        private nznot: NzNotificationService,
        private commondict: CommondictServe,
        @Optional() @Inject(ReuseTabService) private reuseTabService: ReuseTabService,
    ) { }


    appGuid: any;
    appName: string;
    // 布局样式
    widthLeft = 8;
    widthRight = 16;
    isShow = true;
    text='收起';
    activeLike: string;

    // 自定义卡片收缩方法
    toggleCollapsed(): void {
        this.isShow = !this.isShow;
        if(this.isShow === true){
            this.widthLeft = 8;
            this.widthRight = 16;
            this.text = '收起'
        }else{
            this.widthLeft = 2;
            this.widthRight = 22;
            this.text = '展开'
        }
    }
    tabs = [
        {
            name   : '功能',
            router : 'function/funcActive',
            id: 'func'
        },
        {
            name   : '个性化配置',
            router : 'function/appconfig',
            id: 'config'
        }
    ]


    // 应用的数据值
    appItem: AppliaModule = new AppliaModule(); // 搜索值
    appselectId: string;



    ngOnInit() {
        this.activatedRoute.queryParams.subscribe(queryParams => {
            this.appGuid = queryParams.productId;
        });
        if(this.appGuid && this.appGuid != undefined){
            localStorage.setItem('appGuid', this.appGuid);
        }else{
            this.appGuid = localStorage.getItem('appGuid');// 运行环境ID本地存储
        }
        this.appselectId = this.appGuid;
        this.activeLike = 'func';
        this.getFunc(); // 根据guid查询应用信息
        /!*功能初始化信息*!/
        this.configTitle = '修改';
        this.getData();
        this.dictQueryKey();
    }

    // 根据guid查询应用信息
   getFunc() {
       this.utilityService.getData(appConfig.serverUrl + appConfig.API.appDed + '/' + this.appGuid)
           .subscribe(
               (val) => {
                   this.appItem = val.result;
                   this.appName = val.result.appName;
                   this.reuseTabService.title = this.appName + '的应用360'
               }
           );
   }
    // 360切换
    getRouter(it){
        this.activeLike = it; // 复制渲染

        if(it === 'func') {
            this.getData(); // 调用初始化方法
        }

        if(it === 'config') {
            this.configAppTitle = '修改';
            // 枚举值绑定
            this.appgetData(); // 初始化所有个性化配置方法
            this.dictQueryKey(); // 调用业务字典查询
            this.generateFakeData(); // 查询所有业务字典
        }
        // this.router.navigate([it, this.appselectId]);
    }



    funGuid: string; // 功能的id
    modalVisible  = false; // 弹出框默认不打开
    activeModal = false; // 默认列表弹出框不打开
    activeAddModal = false; // 默认列表弹出框不打开
    loading = false;
    expandForm = false;
    isEdit = false; // 是否是修改，默认不是
    isSlash  = false;
    funTitle: string; // 功能弹窗标题
    pageIndex = 1; // 当前页数
    configTitle: string;
    activelistTitle: string; // 行为列表弹框标题
    attrlistTitle: string; // 属性列表弹框标题
    activeModelOpen: boolean;
    selectedRows: any; // 总个数
    isopen:boolean;
    ischeck:boolean;
    // 列表数据
    data: any[] = []; // 表格数据
    headerData = [  // 配置表头内容
        { value: '功能代码', key: 'funcCode', isclick: false },
        // { value: '功能名称', key: 'funcName', isclick: false },
        { value: '功能名称', key: 'funcNames', isclick: false },
        // { value: '功能类型', key: 'funcType', isclick: false },
        { value: '是否启用', key: 'isopen', isclick: false },
        { value: '是否验证权限', key: 'ischeck', isclick: false },
        { value: '显示顺序', key: 'displayOrder', isclick: false },
        // { value: '功能描述', key: 'funcDesc', isclick: false },
        { value: '功能描述', key: 'funcDescs', isclick: false },
    ];
    // 传入按钮层
    moreData = {
        morebutton: true,
        buttons: [
            { key: 'Overview', value: '查看概况' }
        ]
    }
    test: string;
    page: any;
    funcLs: string;
    total: number;
    buttons = [
        {key: 'add', value: '新增功能'}
    ]
    // 基础数据 后期从后台获取
    funcTypes: any;
    // 是否启用
    isOpen: any;
    ifopen = false; // 默认是不禁止选择的

    isCheck: any;

    // 行为的数据类型
    activeItem: FuncattrModule = new FuncattrModule();
    // 功能的数据值
    funcItem: FuncModule = new FuncModule();
    funcAdd: FuncModule = new FuncModule();
    funcActiveItem: FuncModule = new FuncModule();
    codes: any;

    // this.codes = JSON.stringify(this.tokenService.get().codeList);






    // 根据key查询业务字典
    AppdictQueryKey() {
        this.commondict.queryDictKey(appConfig.dictKeyList.funcType)
            .subscribe((val) => {
                this.funcTypes = val.result;
                console.log(this.funcTypes)
            })

        this.commondict.queryDictKey(appConfig.dictKeyList.dictYon)
            .subscribe((val) => {
                this.isOpen = val.result;
                this.isCheck = val.result;
            })
    }


    // 功能新增方法
    // 列表的方法
    addHandler(event) {
        this.isAdd = true;
        if (event === 'add') {
            this.funTitle = '新增功能';
            this.funcAdd = new FuncModule();
            this.funcAdd.isopen = false;
            this.funcAdd.ischeck = false
            this.isopen = false;
            this.ischeck = false;
            this.ifopen = true
            this.isEdit = false;
        } else { // 代表修改，把修改的内容传递进去，重新渲染
            // 枚举值转换方法
            event.ischeck = appConfig.comFunc.isYf(event.ischeck)
            event.isopen = appConfig.comFunc.isYf(event.isopen)
            this.funTitle = '修改功能';
            this.isEdit = true;
            this.ifopen = false; // 不禁选
            this.funcAdd = event;
        }
        this.funcAdd.funcType = 'F';
        this.isSlash = false; // 默认不出现
        this.modalVisible = true;  // 此时点击了列表组件的新增，打开模态框
    }


    funcCodeexit(parameter) {
        let objJson = {
            serviceEntry: parameter,
            guid: this.funcAdd.guid,
        }
        this.utilityService.postData(appConfig.serverUrl  + appConfig.API.existPathParameter, objJson)
            .subscribe(
                (sus) => {
                    if (sus.result) {
                        this.isSlash = true; // 重复
                    } else {
                        this.isSlash = false; // 不重复
                    }
                },
                (error) => {
                    this.nznot.create('error', error.msg , error.msg);
                }
            );
    }

    // 列表传入的翻页数据
    monitorHandler(event) {
        this.pageIndex = event;
        this.getData();
    }

    // 接受子组件删除的数据 单条还是多条
    deleatData(event) {
        this.modal.open({
            title: '是否删除',
            content: '您是否确认删除功能吗?',
            okText: '确定',
            cancelText: '取消',
            onOk: () => {
                // 模拟接口
                this.utilityService.deleatData(appConfig.serverUrl + appConfig.API.funcDel + '/' + event)
                    .subscribe(
                        (val) => {
                            // 修改成功只和的处理逻辑
                            this.nznot.create('success', val.msg , val.msg);
                            if ( !(( this.total - 1) % 10)) {
                                // if ( !(( this.total - this.acfundata.length) % 10)) { // 支持批量删除的方法
                                this.funcItem.pi -- ;
                                this.attrDate();
                            }

                            this.getData();
                        });
            },
            onCancel: () => {

            }
        });

    }

    // 功能批量删除方法
    funcbatchDel(event) {
        this.modal.open({
            title: '是否删除',
            content: '您是否确认删除这' + event.length + '条功能吗?',
            okText: '确定',
            cancelText: '取消',
            onOk: () => {
                let delarray = [];
                for( let i = 0; i < event.length; i++) {
                    delarray.push(event[i].guid);
                }
                let deletaObj = {
                    deleteList: delarray
                }
                this.utilityService.postData(appConfig.serverUrl + appConfig.API.batchDeleteFunc, deletaObj )
                    .subscribe(
                        (val) => {
                            if ( !(( this.total - 1) % 10)) {
                                if ( !(( this.total - this.acfundata.length) % 10)) {
                                    this.funcItem.pi -- ;
                                    this.getData()
                                }// 支持批量删除的方法
                                this.getData();
                            }

                            this.getData();
                            this.selectedRows = [];
                            this.nznot.create('success', val.msg , val.msg);
                        },
                        (error) => {
                            this.nznot.create('error', error.msg , error.msg);
                        });
            },
            onCancel: () => {
                this.selectedRows = [];
                this.getData()
            }
        });
    }

    // 列表按钮方法
    buttonDataHandler(event) {
        console.log(event); // 根据event.value来判断不同的请求，来获取结果和方法或者进行路由的跳转
    }



    // 处理行为代码，跳转、弹出框、其他交互
    isActive(event) {

    }


    selectedRow(event) { // 选中方法，折叠层按钮显示方法

    }


    objJson = {};
    // 搜索框
    search() {
        this.objJson = this.funcItem;
        this.getData(this.funcItem);
    }

    reset() {
        this.funcItem = new FuncModule();
        this.objJson = {};
        this.getData();
    }
    // 根据id查询内容
    getData(options?) {
        if (options) {
            this.pageIndex = 1;
        }

        // 查询功能列表信息
        this.page = {
            condition: this.objJson, // 搜索内容
            page: {
                current: this.pageIndex,
                size: this.funcItem.size,
            }
        };
        this.utilityService.postData(appConfig.serverUrl + appConfig.API.pageQueryFuncByAppId + '/' + this.appGuid, this.page)
            .subscribe(
                (val) => {
                    for (let i = 0; i < val.result.records.length; i++ ) {
                        this.funcLs = val.result.records[i].funcDesc;
                        if(this.funcLs.length> 20){
                            val.result.records[i].funcDescs = (this.funcLs.substr(0,10)+"..."+this.funcLs.substr((this.funcLs.length-10),this.funcLs.length));
                        }else{
                            val.result.records[i].funcDescs = this.funcLs;
                        }
                        this.funcLs = val.result.records[i].funcName;
                        if(this.funcLs.length>20){
                            val.result.records[i].funcNames = (this.funcLs.substr(0,10)+"..."+this.funcLs.substr((this.funcLs.length-10),this.funcLs.length));
                        }else{
                            val.result.records[i].funcNames = this.funcLs;
                        }
                        val.result.records[i].buttonData = [{key: 'dels', value: '删除', if: false},{key: 'activeLook', value: '行为', if: false}, {key: 'attrLook', value: '属性', if: false}];
                    }
                    this.data = val.result.records;
                    this.total = val.result.total;
                }
            );
    }

    // 按钮点击事件
    buttonEvent(event) {
        this.funGuid = event.guid;
        if(event.names.key === 'attrLook') {
            this.activeModelOpen = false; // 功能属性关闭方法
            this.attrlistTitle = '功能 (' + event.funcName + ')下的属性列表'
            this.attrDate(); // 查询属性列表
            this.attrindex = 1; // 重置为1
            this.activeModal = true;
        } else if( event.names.key === 'activeLook') {
            console.log(event)
            this.activelistTitle =  '功能 (' + event.funcName + ')下的行为列表'
            this.queryactiveModal = true;
            this.bahIndex = 1; // 重置为1
            this.funGuid = event.guid;
            this.queryActive(event.guid); // 查询行为
        } else if(event.names.key === 'dels') {
            this.deleatData(event.guid)
        }

    }


    functcancel() {
        this.isAdd = false; // 默认是false
        this.modalVisible = false;
        for(let i = 0; i < this.data.length; i ++ ) {
            if(this.data[i].ischeck === 'Y') {
                this.data[i].ischeck = '是'
            } else {
                this.data[i].ischeck = '否'
            }
            if(this.data[i].isopen === 'Y') {
                this.data[i].isopen = '是'
            } else {
                this.data[i].isopen = '否'
            }
        }
    }


    // 保存方法
    save(isadd) {
        // console.log("-----------------------------------------------------------------")
        // console.log(this.funcAdd)
        if(this.isAdd) {
            const jsonObj = this.funcAdd;
            jsonObj.guidApp = this.appGuid;
            // 新增功能、修改功能逻辑
            if (!this.isEdit) {  // 新增的业务逻辑
                this.utilityService.postData(appConfig.serverUrl + appConfig.API.funcAdd, jsonObj)
                    .subscribe(
                        (val) => {
                            this.nznot.create('success', val.msg , val.msg);
                            this.getData();
                            this.modalVisible = false;
                        },
                        (error) => {
                            this.nznot.create('success', error.msg , error.msg);
                            this.getData();
                        }
                    );

            } else if(this.isEdit) {
                // 修改的保存逻辑
                this.utilityService.putData(appConfig.serverUrl + appConfig.API.funcDel, jsonObj)
                    .subscribe(
                        (val) => {
                            this.nznot.create('success', val.msg , val.msg);
                            this.getData();
                            this.modalVisible = false;
                        },
                        (error) => {
                            this.nznot.create('error', error.msg , error.msg);
                            this.getData();
                        });
            }
        }

    }




    // 行为属性方法内容
    acfundata: any[] = []; // 表格数据
    // 弹窗功能行为
    activeData = [  // 配置表头内容
        { value: '属性类型', key: 'attrType', isclick: false },
        { value: '属性名', key: 'attrKey', isclick: false },
        { value: '属性值', key: 'attrValue', isclick: false },
        { value: '备注', key: 'memo', isclick: false }
    ];
    activeTitle: string; // 列表标题
    ActriceData = {
        morebutton: true,
        buttons: [
            { key: 'Overview', value: '行为概况' }
        ]
    };
    activebuttons = [
        {key: 'add', value: '新增属性'}
    ]
    attrindex = 1; // 属性翻页默认变量
    // 列表翻页方法
    activeHandler(event) {
        this.attrindex = event;
        this.actarrtIndex = event;
        if(!this.activeModelOpen) {
            this.attrDate();
        } else {
            this.ActiveattrDate(); // 查询行为下属性列表
        }


    }
    isAdd: boolean; // 行为新增、修改控制
    // 行为列表方法
    attrDate = function () {
        // 查询功能列表信息
        this.page = {
            page: {
                current: this.attrindex,
                size: this.activeItem.size, // 每页个数
            }
        };
        this.utilityService.postData(appConfig.serverUrl + appConfig.API.acFuncList + '/' + this.funGuid, this.page)
            .subscribe(
                (val) => {
                    this.acfundata = val.result.records;
                    // 后台没有翻译， 应该翻译好的
                    for (let i = 0; i <  this.acfundata.length; i ++ ) {
                        if (this.acfundata[i].attrType === 'B') {
                            this.acfundata[i].attrType = '行为';
                        } else {
                            this.acfundata[i].attrType = '功能';
                        }
                        this.acfundata[i].buttonData = [ {key: 'dels', value: '删除属性', if: false}];
                    }
                    this.total = val.result.total;
                }
            );
    }


    // 行为弹框新增方法
    addActives(event) {
        this.isAdd = true;
        // 打开弹窗就查询
        if (event === 'add') {
            this.activeTitle = '新增属性';
            this.activeItem = new FuncattrModule();
            this.isEdit = false;
        } else { // 代表修改，把修改的内容传递进去，重新渲染
            this.activeTitle = '修改属性';
            this.isEdit = true;
            this.activeItem = event;
        }
        this.activeItem.attrType = 'B';
        this.activeModal = false;
        this.activeAddModal = true;  // 此时点击了列表组件的新增，打开模态框
    }



    // 行为属性保存方法
    activeSave() {
        if(this.isAdd) { // 是功能的新增
            if (!this.activeModelOpen) {
                const jsonObj = this.activeItem;
                jsonObj.guidFunc = this.funGuid;
                if (!this.isEdit) {  // 新增的业务逻辑
                    this.funcItem.guidApp = this.appGuid;
                    this.utilityService.postData(appConfig.serverUrl + appConfig.API.acFuncAttr, jsonObj)
                        .subscribe(
                            (val) => {
                                this.nznot.create('success', val.msg , val.msg);
                                this.attrDate(); // 新增总是回到第一页，跟数据有关，可以参考删除的写法
                                this.activeAddModal = false;
                                this.activeModal = true;
                            },
                            (error) => {
                                this.nznot.create('error', error.msg , error.msg);
                                this.attrDate(); // 查询新增行为下属性列表的方法
                            }
                        );
                } else {
                    // 修改的保存逻辑
                    this.utilityService.putData(appConfig.serverUrl + appConfig.API.acFuncPut, jsonObj)
                        .subscribe(
                            (val) => {
                                this.nznot.create('success', val.msg , val.msg);
                                this.attrDate(); // 查询新增行为下属性列表的方法
                                this.activeAddModal = false;
                                this.activeModal = true;
                            },
                            (error) => {
                                this.nznot.create('error', error.msg , error.msg);
                                this.attrDate(); // 查询新增行为下属性列表的方法
                            });
                }
            } else { // 是行为的属性新增
                const jsonObj = this.activeItem;
                jsonObj.guidFunc = this.activeGuid;
                if (!this.isEdit) {  // 新增的业务逻辑
                    this.funcItem.guidApp = this.appGuid;
                    this.utilityService.postData(appConfig.serverUrl + appConfig.API.acFuncAttr, jsonObj)
                        .subscribe(
                            (val) => {
                                this.nznot.create('success', val.msg , val.msg);
                                this.ActiveattrDate(); // 查询新增行为下属性列表的方法
                                this.activeAddModal = false;
                                this.activeModal = true;
                            },
                            (error) => {
                                this.nznot.create('error', error.msg , error.msg);
                                this.ActiveattrDate(); // 查询新增行为下属性列表的方法
                            }
                        );
                } else {
                    // 修改的保存逻辑
                    this.utilityService.putData(appConfig.serverUrl + appConfig.API.acFuncPut, jsonObj)
                        .subscribe(
                            (val) => {
                                this.nznot.create('success', val.msg , val.msg);
                                this.ActiveattrDate(); // 新增总是回到第一页，跟数据有关，可以参考删除的写法
                                this.activeAddModal = false;
                                this.activeModal = true;
                            },
                            (error) => {
                                this.nznot.create('error', error.msg , error.msg);
                                this.ActiveattrDate(); // 新增总是回到第一页，跟数据有关，可以参考删除的写法
                            });
                }

            }

        }
    }

    // 行为属性取消方法
    acTiveCancel() {
        this.activeAddModal = false;  // 关闭行为新增弹窗
        this.activeModal = true;    // 打开行为列表弹窗
        this.isAdd = false; // 不调用新增修改方法
    }

    // 属性弹窗关闭方法
    activeModel() {
        if(this.activeModelOpen) { // 行为属性，关闭弹窗，打开行为弹窗
            this.activeModal = false;
            this.queryactiveModal = true;
        } else {
            this.activeModal = false;
        }
    }

    // 列表弹窗删除属性方法
    deleatActiveData(event) {
        this.activeModal = false;
        if(!this.activeModelOpen) { // 是功能的删除
            this.modal.open({
                title: '是否删除',
                content: '您是否确认删除该属性吗?',
                okText: '确定',
                cancelText: '取消',
                onOk: () => {
                    // 模拟接口
                    this.utilityService.deleatData(appConfig.serverUrl + appConfig.API.acFuncDel + '/' + event.guid)
                        .subscribe(
                            (val) => {
                                // 修改成功只和的处理逻辑
                                this.nznot.create('success', val.msg , val.msg);
                                if ( !(( this.total - 1) % 10)) {
                                    // if ( !(( this.total - this.acfundata.length) % 10)) { // 支持批量删除的方法
                                    this.activeItem.pi -- ;
                                }
                                this.attrDate();
                                this.activeModal = true;
                            });
                },
                onCancel: () => {
                    this.activeModal = true;
                    this.attrDate();
                }
            });
        } else {
            this.modal.open({
                title: '是否删除',
                content: '您是否确认删除该属性吗?',
                okText: '确定',
                cancelText: '取消',
                onOk: () => {
                    // 模拟接口
                    this.utilityService.deleatData(appConfig.serverUrl + appConfig.API.acFuncDel + '/' + event.guid)
                        .subscribe(
                            (val) => {
                                // 修改成功只和的处理逻辑
                                this.nznot.create('success', val.msg , val.msg);
                                if ( !(( this.total - 1) % 10)) {
                                    // if ( !(( this.total - this.acfundata.length) % 10)) { // 支持批量删除的方法
                                    this.activeItem.pi -- ;
                                }
                                this.ActiveattrDate();
                                this.activeModal = true;
                            });
                },
                onCancel: () => {
                    this.activeModal = true;
                    this.ActiveattrDate();
                }
            });
        }
    }

    // 批量删除属性方法
    attrbatchDel(event) {
        this.activeModal = false;
        if(!this.activeModelOpen) { // 是功能的删除
            this.modal.open({
                title: '是否删除',
                content: '您是否确认删除这' + event.length + '条属性吗?',
                okText: '确定',
                cancelText: '取消',
                onOk: () => {
                    let delarray = [];
                    for( let i = 0; i < event.length; i++) {
                        delarray.push(event[i].guid);
                    }
                    let deletaObj = {
                        deleteList: delarray
                    }
                    this.utilityService.postData(appConfig.serverUrl + appConfig.API.attrbatchDelete, deletaObj )
                        .subscribe(
                            (val) => {
                                // 修改成功只和的处理逻辑
                                this.nznot.create('success', val.msg , val.msg);
                                if ( !(( this.total - 1) % 10)) {
                                    // if ( !(( this.total - this.acfundata.length) % 10)) { // 支持批量删除的方法
                                    this.activeItem.pi -- ;
                                }
                                this.attrDate();
                                this.selectedRows = [];
                                this.activeModal = true;
                            });
                },
                onCancel: () => {
                    this.activeModal = true;
                    this.selectedRows = [];
                    this.attrDate();
                }
            })
        } else {
            this.modal.open({
                title: '是否删除',
                content: '您是否确认删除这' + event.length + '条数据吗?',
                okText: '确定',
                cancelText: '取消',
                onOk: () => {
                    let delarray = [];
                    for( let i = 0; i < event.length; i++) {
                        delarray.push(event[i].guid);
                    }
                    let deletaObj = {
                        deleteList: delarray
                    }
                    this.utilityService.postData(appConfig.serverUrl + appConfig.API.attrbatchDelete, deletaObj )
                        .subscribe(
                            (val) => {
                                // 修改成功只和的处理逻辑
                                this.nznot.create('success', val.msg , val.msg);
                                if ( !(( this.total - 1) % 10)) {
                                    // if ( !(( this.total - this.acfundata.length) % 10)) { // 支持批量删除的方法
                                    this.activeItem.pi -- ;
                                }
                                this.ActiveattrDate();
                                this.activeModal = true;
                            });
                },
                onCancel: () => {
                    this.activeModal = true;
                    this.ActiveattrDate();
                }
            })
        }


    }

    // 列表页右侧方法
    activeButton(event) {
        if(event.names.key === 'dels') {
            this.deleatActiveData(event);
        }
    }



    // 行为方法
    acfunActivedata = []; // 行为数据
    activeText: string; // 行为弹框名称
    queryactiveModal = false; // 行为列表弹框
    modalActiveVisible = false; // 行为新增弹框
    addActiveButtons = [
        {key: 'add', value: '新增行为'}
    ]
    activesTitle = '修改';
    isActiveOpen = false; // 是否禁选
    isactiveEdit: boolean; // 是新增行为还是修改行为判断变量
    ActiveheaderData = [  // 配置表头内容
        { value: '行为代码', key: 'funcCode', isclick: false },
        { value: '行为名称', key: 'funcName', isclick: false },
        { value: '是否启用', key: 'isopen', isclick: false },
        { value: '是否验证权限', key: 'ischeck', isclick: false },
        { value: '显示顺序', key: 'displayOrder', isclick: false },
        { value: '功能描述', key: 'funcDesc', isclick: false },
    ];
    activeGuid: string; // 行为的guid
    bahIndex = 1;
    // 查询行为接口
    queryActive(item) {
        this.page = {
            page: {
                current: this.bahIndex,
                size: this.activeItem.size, // 每页个数
            }
        };
        this.utilityService.postData(appConfig.serverUrl + appConfig.API.pageQueryBehaveByFuncId + '/' + item, this.page)
            .subscribe(
                (val) => {
                    // 后台没有翻译， 应该翻译好的
                    for (let i = 0; i < val.result.records.length; i++ ) {
                        val.result.records[i].buttonData = [{key: 'dels', value: '删除', if: false}, {key: 'attr', value: '属性', if: false}];
                    }
                    this.acfunActivedata = val.result.records;
                    this.total = val.result.total;
                }
            );
    };

    // 新增行为接口
    addActivesHandler(event) {
        this.isAdd = true;
        if (event === 'add') {
            this.funcActiveItem = new FuncModule();
            this.isActiveOpen = true;
            this.isactiveEdit = false; // 是新增,不是修改
            this.funTitle = '新增行为';
            this.funcActiveItem.isopen = 'Y'
            this.funcActiveItem.ischeck = 'Y'
            this.queryactiveModal = false; // 关闭查询列表
            this.modalActiveVisible = true;  // 打开新增列表
        } else { // 代表修改，把修改的内容传递进去，重新渲染
            this.isactiveEdit = true; // 是修改,不是新增
            this.funTitle = '修改行为';
            event.ischeck = appConfig.comFunc.isYf(event.ischeck)
            event.isopen = appConfig.comFunc.isYf(event.isopen)
            this.isActiveOpen = false; // 不禁用
            this.queryactiveModal = false; // 关闭查询列表
            this.modalActiveVisible = true; // 打开新增行为列表
            this.funcActiveItem = event;
        }
        this.funcActiveItem.funcType = 'B'; // 默认是行为
    }

    // 行为翻页
    addActiveHandler(event) {
        this.bahIndex = event;
        this.queryActive(this.funGuid);
    }


    activeButonEvent(event) {
        if(event.names.key === 'dels') {
            this.DelActive(event.guid)
        } else {
            this.activeGuid = event.guid;
            this.activeModal = true; // 属性打开
            this.queryactiveModal = false; // 行为列表弹窗关闭
            this.attrlistTitle = '行为 (' + event.funcName + ')下的属性列表'
            this.actarrtIndex = 1; // 重置为1
            this.activeModelOpen = true; // 行为属性关闭方法
            this.ActiveattrDate(); // 查询行为下属性
        }
    }

    // 新增、修改行为方法
    modalActiveVisiblesave() {
        if (this.isAdd) { // 因为返回也会进入方法，用isAdd来控制
            const jsonObj = this.funcActiveItem;
            jsonObj.guidFunc = this.funGuid;
            // 枚举值转换
            // 新增功能、修改功能逻辑
            this.funcActiveItem.guidApp = this.appGuid;
            if (!this.isactiveEdit) {  // 新增的业务逻辑
                this.utilityService.postData(appConfig.serverUrl + appConfig.API.funcAdd, jsonObj)
                    .subscribe(
                        (val) => {
                            this.nznot.create('success', val.msg , val.msg);
                            this.queryActive(this.funGuid)
                            this.modalActiveVisible = false;
                            this.queryactiveModal = true;
                        },
                        (error) => {
                            this.nznot.create('error', error.msg , error.msg);
                            this.queryActive(this.funGuid)
                        }
                    );
            } else if( this.isactiveEdit) {
                // 修改的保存逻辑
                this.utilityService.putData(appConfig.serverUrl + appConfig.API.funcDel, jsonObj)
                    .subscribe(
                        (val) => {
                            this.nznot.create('success', val.msg , val.msg);
                            this.queryActive(this.funGuid)
                            this.modalActiveVisible = false;
                            this.queryactiveModal = true;
                        },
                        (error) => {
                            this.nznot.create('error', error.msg , error.msg);
                            this.queryActive(this.funGuid)
                        });
            }

        }
    }

    // 新增、修改行为取消方法
    ActiveCancel() {
        this.modalActiveVisible = false;
        this.queryactiveModal = true;
        this.isAdd = false;
        for(let i = 0; i < this.acfunActivedata.length; i ++ ) {
            if(this.acfunActivedata[i].ischeck === 'Y') {
                this.acfunActivedata[i].ischeck = '是'
            } else {
                this.acfunActivedata[i].ischeck = '否'
            }
            if(this.acfunActivedata[i].isopen === 'Y') {
                this.acfunActivedata[i].isopen = '是'
            } else {
                this.acfunActivedata[i].isopen = '否'
            }
        }
    }


    // 删除行为方法
    DelActive(event) {
        this.queryactiveModal = false; // 关闭弹窗
        this.modal.open({
            title: '是否删除',
            content: '您是否确认删除该行为吗?',
            okText: '确定',
            cancelText: '取消',
            onOk: () => {
                // 模拟接口
                this.utilityService.deleatData(appConfig.serverUrl + appConfig.API.funcDel + '/' + event)
                    .subscribe(
                        (val) => {
                            // 修改成功只和的处理逻辑
                            this.nznot.create('success', val.msg , val.msg);
                            if ( !(( this.total - 1) % 10)) {
                                this.funcItem.pi -- ;
                                this.queryActive(this.funGuid)
                            }
                            this.queryactiveModal = true;
                            this.queryActive(this.funGuid)
                        });
            },
            onCancel: () => {
                this.queryactiveModal = true;
                this.queryActive(this.funGuid)
            }

        });
    }

    // 批量删除行为的方法
    activebatchDel(event) {
        console.log(event)
        this.queryactiveModal = false; // 关闭弹窗
        this.modal.open({
            title: '是否删除',
            content: '您是否确认删除这' + event.length + '条行为数据吗?',
            okText: '确定',
            cancelText: '取消',
            onOk: () => {
                let delarray = [];
                for( let i = 0; i < event.length; i++) {
                    delarray.push(event[i].guid);
                }
                let deletaObj = {
                    deleteList: delarray
                }

                this.utilityService.postData(appConfig.serverUrl + appConfig.API.batchDeleteFunc, deletaObj )
                    .subscribe(
                        (val) => {
                            // 修改成功只和的处理逻辑
                            this.nznot.create('success', val.msg , val.msg);
                            if ( !(( this.total - 1) % 10)) {
                                this.funcItem.pi -- ;
                                this.queryActive(this.funGuid)
                            }
                            this.queryactiveModal = true;
                            this.selectedRows = [];
                            this.queryActive(this.funGuid)
                        });
            },
            onCancel: () => {
                this.queryactiveModal = true;
                this.selectedRows = [];
                this.queryActive(this.funGuid)
            }
        });
    }

    switchchange(item, status) {
        if(item === 'isopen') {
            if(status){
                this.funcAdd.isopen = 'Y';
            }else{
                this.funcAdd.isopen = 'N';
            }
        }
        if(item === 'ischeck'){
            if(status) {
                this.funcAdd.ischeck = 'Y';
            }else{
                this.funcAdd.ischeck = 'N';
            }
        }
    }

    // 查询行为下属性
    actarrtIndex = 1; // 默认为第一页
    // 行为列表方法
    ActiveattrDate = function () {
        // 查询功能列表信息
        this.page = {
            page: {
                current: this.actarrtIndex, // 当前页码
                size: this.activeItem.size, // 每页个数
            }
        };
        this.utilityService.postData(appConfig.serverUrl + appConfig.API.acFuncList + '/' + this.activeGuid, this.page)
            .subscribe(
                (val) => {
                    this.acfundata = val.result.records;
                    // 后台没有翻译， 应该翻译好的
                    for (let i = 0; i <  this.acfundata.length; i ++ ) {
                        if (this.acfundata[i].attrType === 'B') {
                            this.acfundata[i].attrType = '行为';
                        } else {
                            this.acfundata[i].attrType = '功能';
                        }
                        this.acfundata[i].buttonData = [ {key: 'dels', value: '删除属性', if: false}];
                    }
                    this.total = val.result.total;
                }
            );
    }







    /!*--------------------------个性化配置页面---------------------------------*!/
    // 绑定类
    appConfigitem: AppConfigModule = new AppConfigModule();
    appConfigAdd: AppConfigModule = new AppConfigModule();
    configAppTitle: string; // 默认的修改按钮的名称
    isappEdit: boolean; // 是否是修改
    apppage: any; // 翻页方法
    appdata: any[] = []; // 表格数据
    appconfigtotal: number; // 总数数据
    appConfigVisible = false; // 弹出框默认false
    appisopen: any // 弹出框默认false
    appconfigbuttons = [
        {key: 'add', value: '新增个性化配置'}
    ]
    selectedappRows: any; // 总数
    // 表格表头
    appheaderData = [  // 配置表头内容
        { value: '配置类型', key: 'configType', isclick: false },
        { value: '配置名', key: 'configName', isclick: false },
        { value: '配置值字典', key: 'dictName', isclick: false },
        { value: '配置风格', key: 'configStyle', isclick: false },
        { value: '默认配置值', key: 'valueName', isclick: false },
        { value: '是否启用', key: 'enabled', isclick: false },
        { value: '显示顺序', key: 'displayOrder', isclick: false },
        { value: '配置描述说明', key: 'configDesc', isclick: false },
    ];

    // 枚举值
    configType: any; // 配置类型
    configDict = []; // 配置值字典
    configValue: any; // 配置值字典默认值
    index = 0; // 查询所有业务字典需要的
    configStyle: any; // 配置风格
    apppageIndex = 1; // 当前页数




    // 所有业务字典,不分页
    generateFakeData() {
        this.apppage = {
            page: {
                current: this.index,
                size: 10000, // 先写死长度
            }
        };
        // 调用服务来获取列表节点操作
        this.utilityService.postData(appConfig.serverUrl + appConfig.API.sysDictList ,  this.apppage)
            .subscribe(
                (val) => {
                    for (let i = 0; i < val.result.records.length; i++) {
                        this.configDict.push(val.result.records[i]);
                        this.index++;
                    }
                });
    }

    // selete监听方法
    checkSelect(guid) {
        this.appConfigAdd.configValue = null;
        // 根据key查询对应业务字典项
        this.utilityService.getData(appConfig.serverUrl + appConfig.API.queryListByDictId + '/' + guid)
            .subscribe(
                (val) => {
                    if (val.result.length > 0) {
                        this.configValue = val.result;
                    } else {
                        this.appConfigAdd.configValue = null;
                        this.configValue = [];
                    }


                }
            );
    }





    // 根据key查询业务字典
    dictQueryKey() {
        this.commondict.queryDictKey(appConfig.dictKeyList.dictType)
            .subscribe((val) => {
                this.configType = val.result;
            })

        this.commondict.queryDictKey(appConfig.dictKeyList.styleColor)
            .subscribe((val) => {
                this.configStyle = val.result;
            })


        this.commondict.queryDictKey(appConfig.dictKeyList.dictYon)
            .subscribe((val) => {
                this.appisopen = val.result;
            })
    }

    // 初始化方法
    appgetData(option?) {
        if (option) {
            this.apppageIndex = 1;
        }
        this.apppage = {
            condition: this.objJson, // 搜索内容
            page: {
                current: this.apppageIndex,
                size: this.appConfigitem.size,
            }
        };
        this.utilityService.postData(appConfig.serverUrl + appConfig.API.listByAppId + '/' + this.appGuid, this.apppage)
            .subscribe(
                (val) => {
                    console.log(val.result)
                    for (let i = 0; i < val.result.records.length; i++ ) {
                        if(val.result.records[i].configType === 'a') {
                            val.result.records[i].configType = '应用';
                        } else {
                            val.result.records[i].configType = '系统';
                        }

                        if(val.result.records[i].enabled === 'N') {
                            val.result.records[i].enabled = '否';
                        } else {
                            val.result.records[i].enabled = '是';
                        }

                        val.result.records[i].buttonData = [{key: 'dels', value: '删除', if: false}];
                    }
                    this.appdata = val.result.records;
                    this.appconfigtotal = val.result.total;
                }
            );
    }

    addappHandler(event) {
        console.log(event)
        if (event === 'add') {
            this.configAppTitle = '新增个性化配置';
            this.appConfigAdd = new AppConfigModule();
            this.isappEdit = false;
        } else { // 代表修改，把修改的内容传递进去，重新渲染
            if(event.configType === '应用') {
                event.configType = 'a'
            } else {
                event.configType = 's'
            }

            if(event.enabled === '是') {
                event.isopen = 'Y'
            } else {
                event.isopen = 'N'
            }

            this.configAppTitle = '修改个性化配置';
            this.isappEdit = true;
            this.appConfigAdd = event;
        }
        this.appConfigVisible = true;
    }

    // 翻页
    appmonitorHandler(event) {
        this.apppageIndex = event;
        this.appgetData();
    }

    // 删除的方法
    apdeleatData(event) {
        this.modal.open({
            title: '是否删除',
            content: '您是否确认删除该个性化配置吗?',
            okText: '确定',
            cancelText: '取消',
            onOk: () => {
                // 模拟接口
                this.utilityService.deleatData(appConfig.serverUrl + appConfig.API.acAppConfig + '/' + event)
                    .subscribe(
                        (val) => {
                            // 修改成功只和的处理逻辑
                            this.nznot.create('success', val.msg , val.msg);
                            if ( !(( this.appconfigtotal - 1) % 10)) {
                                // if ( !(( this.total - this.acfundata.length) % 10)) { // 支持批量删除的方法
                                this.apppageIndex --;
                            }
                            this.appgetData();
                        },
                        (error) => {
                            this.nznot.create('error', error.msg , error.msg);
                        });
            },
            onCancel: () => {
                this.appgetData();
            }
        });
    }


    // 批量删除的方法
    configbatchDel(event) {
        this.modal.open({
            title: '是否删除',
            content: '您是否确认删除这' + event.length + '条个性化配置吗吗?',
            okText: '确定',
            cancelText: '取消',
            onOk: () => {
                let delarray = [];
                for( let i = 0; i < event.length; i++) {
                    delarray.push(event[i].guid);
                }
                let deletaObj = {
                    deleteList: delarray
                }
                this.utilityService.postData(appConfig.serverUrl + appConfig.API.appConfigbathDel, deletaObj )
                    .subscribe(
                        (val) => {

                            this.selectedappRows = []
                            if ( !(( this.appconfigtotal - 1) % 10)) {
                                // if ( !(( this.total - this.acfundata.length) % 10)) { // 支持批量删除的方法
                                this.apppageIndex --;
                            }
                            this.appgetData();
                            this.nznot.create('success', val.msg , val.msg);
                        },
                        (error) => {
                            this.nznot.create('error', error.msg , error.msg);
                        });
            },
            onCancel: () => {
                this.selectedRows = []
                this.appgetData();
            }
        });
    }


    // 按钮点击事件
    appbuttonEvent(event) {
        if(event.names.key === 'dels') {
            this.apdeleatData(event.guid); // 删除方法
        }
    }



    // 搜索框
    appsearch() {
        this.objJson = this.appConfigitem;
        this.appgetData(this.appConfigitem);
    }

    appreset() {
        this.appConfigitem = new AppConfigModule(); // 重置
        this.objJson = {};
        this.appgetData();
    }

    appsave(item) {
        const jsonObj = this.appConfigAdd;
        jsonObj.guidApp = this.appGuid;
        // 新增功能、修改功能逻辑
        if (!this.isappEdit) {  // 新增的业务逻辑
            this.utilityService.postData(appConfig.serverUrl + appConfig.API.acAppConfig, jsonObj)
                .subscribe(
                    (val) => {
                        this.nznot.create('success', val.msg , val.msg);
                        this.appgetData();
                    },
                    (error) => {
                        this.nznot.create('error', error.msg , error.msg);
                        this.appgetData();
                    }
                );
            this.appConfigVisible = false;
        } else if (this.isappEdit) {
            // 修改的保存逻辑
            this.utilityService.putData(appConfig.serverUrl + appConfig.API.acAppConfig, jsonObj)
                .subscribe(
                    (val) => {
                        this.nznot.create('success', val.msg , val.msg);
                        this.appgetData();
                    },
                    (error) => {
                        this.nznot.create('error', error.msg , error.msg);
                        this.appgetData();
                    });
            this.appConfigVisible = false;
        }
    }

}
*/
